import type { ICreateUserParams, IUserInfo } from './types'
import { http } from '@/utils/http/axios'

export interface BasicResponseModel<T = any> {
  code: number
  message: string
  result: T
}

/**
 * @description: 用户登录
 */
export function login(params: any) {
  return http.request<BasicResponseModel>(
    {
      url: '/login',
      method: 'POST',
      params,
    },
    {
      isTransformResponse: false,
    },
  )
}

/**
 * @description: 获取用户信息
 */
export function getUserInfo(phone: string) {
  return http.request<IUserInfo>({
    url: `/h5/user/info/${phone}`,
    method: 'get',
  }).then(res => res)
}

/**
 * @description: 用户登出
 */
export function doLogout() {
  return http.request({
    url: '/logout',
    method: 'POST',
  })
}

/**
 * @description: 用户修改密码
 */
export function changePassword(params: any, uid: any) {
  return http.request(
    {
      url: `/user/u${uid}/changepw`,
      method: 'POST',
      params,
    },
    {
      isTransformResponse: false,
    },
  )
}

/**
 * 创建用户
  POST /h5/user/register
  接口ID：217397191
  接口地址：https://app.apifox.com/link/project/5160540/apis/api-217397191
 */
export function createUser(data: ICreateUserParams) {
  return http.request({
    url: `/h5/user/register`,
    method: 'POST',
    data,
  })
}

/**
 * 更新头像
 */

/**
 * 文件上传
 */
export function uploadFile(data: any) {
  return http.request({
    url: `/file/upload`,
    method: 'POST',
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    data,
  })
}

/**
 * 更新用户头像
 */
export function updateUserAvatar(phone: any, headPic: string) {
  return http.request(
    {
      url: `/h5/user/info/${phone}`,
      method: 'put',
      data: {
        headPic,
      },
    },
  )
}
